<template>
  <el-dialog :visible.sync="isShow" title="分配角色">
    <el-checkbox-group v-model="checkArr">
      <el-checkbox v-for="item in list" :key="item.id" :label="item.id">{{
        item.name
      }}</el-checkbox>
    </el-checkbox-group>
    <template #footer>
      <div>
        <el-button type="primary" @click="submit">提交</el-button>
        <el-button @click="closeEvent">取消</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script>
import { sysRole } from '@/api/setting.js'
import { sysUser } from '@/api/user'
import { sysUserAssignRoles } from '@/api/employees.js'
export default {
  data () {
    return {
      isShow: false,
      list: [],
      checkArr: [],
      id: ''
    }
  },
  created () {
    this.getData()
  },
  methods: {
    closeEvent () {
      this.isShow = false
      // 关闭时清空选择
      this.checkArr = []
    },
    async getData () {
      const res = await sysRole({ pagesize: 300 })
      this.list = res.data.rows
      console.log('角色列表:', res)
    },
    async getUserInfo (id) {
      this.id = id
      const res = await sysUser(id)
      this.checkArr = res.data.roleIds || []
      console.log('当前点击项员工详情：', res)
    },
    // 提交
    async submit () {
      await sysUserAssignRoles(this.id, this.checkArr)
      this.$message.success('分配角色成功')
      this.closeEvent()
    }
  }
}
</script>

<style></style>
